<template>
  <div class="infoCont">
    <div class="info">
      <div class="cont">
        <div class="top">
          <img :src="form.avatar" mode="aspectFill" />
          <div>
            <span>{{form.username}}</span>
            <i-rate
              :value="form.goodsAssess"
              :disabled="true"
              class="rateClasee"
            />
          </div>
        </div>
        <p class="middle">
          <span>评论内容：</span>
          {{form.content}}
        </p>
        <div class="imgList">
          <img :src="form.img1" mode="aspectFill" />
          <img :src="form.img2" mode="aspectFill" />
          <img :src="form.img3" mode="aspectFill" />
        </div>
        <div class="replyCont" v-if="form.reply">回复内容：{{form.reply}}</div>
        <div class="replyContNo" v-else>暂时回复</div>
      </div>
    </div>
    <div class="shopInfo">
      <div class="cont">
        <p class="title">商品</p>
        <div class="shopCont">
          <div class="left">
            <img :src="shopForm.goodsImg" mode="aspectFill" />
            <div>
              <span
                v-if="orderForm.orderGoodsList"
              >规格：{{orderForm.orderGoodsList[0].goodsSpecName}}</span>
              <span v-else>无</span>
              <span>{{shopForm.goodsName}}</span>
              <!-- <span>库存：{{shopForm.goodsStock}}</span> -->
            </div>
          </div>
          <div class="right">
            <span>￥{{shopForm.goodsCost}}</span>
            <span>×{{orderForm.orderGoodsList[0].goodsNum}}</span>
            <!-- <span>×{{shopForm.saleNum}}</span>销量 -->
          </div>
        </div>
      </div>
    </div>
    <div class="expressInfo">
      <div class="cont">
        <span>订单编号：{{shopForm.goodsNo}}</span>
        <span>服务方式：{{shopForm.shippingMode === '0' ? '物流' : shopForm.shippingMode === '1' ? '到店自提' : shopForm.shippingMode === '2' ? '商家上门' : '店内消费'}}</span>
      </div>
    </div>
    <div class="btnBox">
      <!-- <span @click="deleteClick">删除评论</span> -->
      <span @click="replyClick">回复</span>
    </div>
    <div class="replyBox" v-if="replyShow">
      <div class="zz" @click="zzClick"></div>
      <div class="reply">
        <textarea
          v-model="replyTextarea"
          class="input-area"
          placeholder="请输入评论内容"
          placeholder-class="placeholder-part"
        ></textarea>
        <button
          class="replyBtn"
          @click="confirmReplyClick"
          size="small"
          shape="circle"
          type="primary"
        >发表</button>
      </div>
    </div>
  </div>
</template>

<script>
import {
  FIND_SHOP_GOODS_INFO,
  FIND_ORDER_NO_INFO,
  ASSESS_REPLY_ASSESS
} from '@/api'

export default {
  components: {},
  props: {},
  data () {
    return {
      form: {},
      shopForm: {},
      orderForm: {},
      formTest: {
        anonymous: 'N',
        assessGoodsId: 30,
        avatar:
          'https://akk028wkf.oss-cn-beijing.aliyuncs.com/SHOP/20171228/JKLE-327792_full.jpg',
        content: '好',
        createDate: '2018-12-19 10:57:32'.slice(0, 10),
        goodsAssess: 5,
        img1: '',
        img2: '',
        img3: '',
        username: '测试'
      },
      replyTextarea: '',
      replyShow: false
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  onShow () {
    this.init()
    this._findOrderNoInfo()
    this._findOrderNoInfo2()
  },
  onUnload () {
    this.$cookie.remove('reply-info')
  },
  methods: {
    confirmReplyClick () {
      if (!this.replyTextarea) {
        this.$toast('评论内容不能为空')
        return false
      }
      this._assessReplyAssess()
    },
    zzClick () {
      this.replyShow = false
    },
    replyClick () {
      this.replyShow = true
    },
    deleteClick () {
      const vm = this
      vm.replyTextarea = ''
      vm
        .$dialog('删除评论？', '')
        .then(() => {
          vm.$router.go(-1)
          vm._assessReplyAssess()
        })
        .catch(() => {
          console.log('点击了取消')
        })
    },
    _assessReplyAssess () {
      const vm = this
      let item = JSON.parse(vm.$root.$mp.query.val)

      ASSESS_REPLY_ASSESS(vm.replyTextarea, item.assessGoodsId)
        .then(r => {
          if (r.data.code === '0') {
            vm.$alert('操作成功', '').then(() => {
              vm.$router.go(-1)
            })
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.error(e)
        })
    },
    _findOrderNoInfo () {
      const vm = this
      let item = JSON.parse(vm.$root.$mp.query.val)
      FIND_SHOP_GOODS_INFO(item.goodsNo)
        .then(r => {
          if (r.data.code === '0') {
            vm.shopForm = r.data.data
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.info(e)
        })
    }, // 查询单条订单信息
    _findOrderNoInfo2 () {
      const vm = this
      let item = JSON.parse(vm.$root.$mp.query.val)
      FIND_ORDER_NO_INFO(item.orderNo)
        .then(r => {
          if (r.data.code === '0') {
            vm.orderForm = r.data.data
            vm.shopForm.shippingMode = r.data.data.shippingMode
            // vm.shopForm.goodsSpecName =
            //   r.data.data.orderGoodsList[0].goodsSpecName
            // vm.shopForm.goodsNum = r.data.data.orderGoodsList[0].goodsNum
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.info(e)
        })
    }, // 查询单条订单信息
    init () {
      const vm = this
      vm.replyShow = false
      vm.replyTextarea = ''
      vm.form = vm.$cookie.get('reply-info')
    }
  }
}
</script>

<style lang="scss" scoped>
@import 'static/styles/color.scss';
.infoCont {
  .info {
    width: 100%;
    // border-top: 1px solid #c4c4c4;
    // border-bottom: 1px solid #c4c4c4;
    .cont {
      width: 90%;
      margin: 20px auto;
      .top {
        display: flex;
        img {
          width: 40px;
          height: 40px;
          border-radius: 50px;
        }
        div {
          display: flex;
          flex-direction: column;
          justify-content: flex-start;
          font-size: 14px;
          margin-left: 10px;
        }
      }
      .middle {
        margin: 15px 0;
        color: #000;
        font-size: 14px;
        span {
          color: #b1b0ab;
        }
      }
      .imgList {
        display: flex;
        img {
          width: 80px;
          height: 80px;
          margin-right: 15px;
        }
      }
      .replyCont {
        font-size: 14px;
        color: #e51e25;
      }
      .replyContNo {
        font-size: 14px;
        color: #666;
      }
    }
  }
  .shopInfo {
    width: 100%;
    // border-top: 1px solid #c4c4c4;
    // border-bottom: 1px solid #c4c4c4;
    margin: 20px 0;
    .cont {
      width: 95%;
      margin: auto;
      .title {
        font-size: 12px;
        color: #666;
        margin-top: 20px;
      }
      .shopCont {
        margin: 10px 0 30px;
        display: flex;
        justify-content: space-between;
        .left {
          display: flex;
          align-items: center;
          img {
            width: 60px;
            height: 60px;
            margin-right: 10px;
          }
          div {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: flex-start;
            font-size: 14px;
            color: #666;
            width: 240px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
        .right {
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: flex-end;
          color: #e53c46;
          font-size: 14px;
        }
      }
    }
  }
  .expressInfo {
    width: 100%;
    // border-top: 1px solid #c4c4c4;
    // border-bottom: 1px solid #c4c4c4;
    margin: 20px 0;
    .cont {
      width: 90%;
      margin: 20px auto;
      display: flex;
      flex-direction: column;
      font-size: 12px;
      color: #666;
      span {
        margin: 3px 0;
      }
    }
  }
  .btnBox {
    display: flex;
    justify-content: flex-end;
    margin-top: 100px;
    // span {
    //   width: 85px;
    //   text-align: center;
    //   line-height: 20px;
    //   border: 2px solid #e51e25;
    //   color: #e51e25;
    //   font-size: 12px;
    //   margin-right: 10px;
    // }
    span {
      // width: 85px;
      // text-align: center;
      // line-height: 20px;
      padding: 8px 18px;
      border-radius: 4px;
      font-size: 12px;
      margin-right: 10px;
      background: #5d93fd;
      color: #fff;
    }
  }
  .replyBox {
    .zz {
      position: fixed;
      z-index: 2;
      top: 0;
      left: 0;
      height: 100%;
      width: 100%;
      background-color: #000000;
      opacity: 0.3;
    }
    .reply {
      width: 320px;
      height: 220px;
      border: 2px solid #eee;
      background: #fff;
      border-radius: 4px;
      position: absolute;
      z-index: 3;
      left: 0;
      top: 0;
      bottom: 0;
      right: 0;
      margin: auto;
      overflow: auto;
      .input-area {
        width: 95%;
        margin: 10px auto 0;
        font-size: 14px;
      }
      .replyBtn {
        text-align: center;
        vertical-align: middle;
        touch-action: manipulation;
        cursor: pointer;
        background-image: none;
        white-space: nowrap;
        user-select: none;
        font-size: 14px;
        border-radius: 2px;
        border: 0 !important;
        position: relative;
        text-decoration: none;
        height: 44px;
        line-height: 44px;
        box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
        color: #fff !important;
        margin: 10px;
        background: #508ff9;
        border-radius: 5px;
      }
    }
  }
}
</style>
